<template>
  <div class="app-main-container">
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clearFilters"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table"
    >
      <el-table-column
        v-for="item in propList"
        :key="item.label"
        align="center"
        :label="item.label"
        :prop="item.prop"
        :min-width="item.minWidth"
        show-overflow-tooltip
      />
      <el-table-column
        label="操作"
        min-width="160"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            v-if="meta.indexOf('DicEdit') > -1"
            v-preventReClick
            type="text"
            @click="handleEdit(scope.row)"
          >配置</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Paginations
      :total="total"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
    <Edit v-if="isShowEdit" ref="EditRef" @success="getList" @close="isShowEdit = false" />
  </div>
</template>

<script>
import { DictListPost } from '@/api'
import { propList, queryFormConfig, rules } from './config'
import QueryForm from '@/components/QueryForm'
import Edit from './edit.vue'
export default {
  components: {
    QueryForm,
    Edit
  },
  data() {
    return {
      propList,
      queryFormConfig,
      rules,
      listLoading: false,
      list: [],
      meta: [],
      pagination: {
        page: 1,
        rows: 10
      },
      total: 0,
      filters: {},

      isShowEdit: false
    }
  },
  created() {
    this.meta = this.$route.meta.buttons || []
    this.getList()
    // this.getVenueList()
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  activated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  methods: {
    handleEdit(row) {
      this.isShowEdit = true
      this.$nextTick(() => {
        this.$refs.EditRef.isShowModel = true
        this.$refs.EditRef.param = { ...row }
      })
    },
    handleDel() { },
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    handlePublish() {},
    getList(page) {
      const { pagination, filters: param } = this
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      this.listLoading = true
      DictListPost({ pagination, param }).then(res => {
        this.listLoading = false
        if (res.errorCode === '000000') {
          this.list = res.recordList
          this.total = res.totalCount
        }
      }).catch(() => {
        this.listLoading = false
      })
    },
    // 清空筛选项
    clearFilters() {
      this.filters = {}
      this.getList(1)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
